package net.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.ko.http.objects.KRequest;
import net.ko.mapping.IMappingControl;

public class Control implements IMappingControl {

	@Override
	public boolean isValid(HttpServletRequest request,
			HttpServletResponse response) {
		   
		    boolean result = false;
			if(request.getSession().getAttribute("activeVisiteur") != null)
			{
		    	result= true;
		    }
			else
			{
		    	result  = false;
		    }
		 
		return result;
	}

	@Override
	public void onInvalidControl(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			request.setAttribute("erreur", "Vous devez vous connectez");
			KRequest.forward("/index.do", request, response,"erreur=Vous devez vous connectez");
		} catch (ServletException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public boolean beforeProcessAction(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		return true;
	}

}
